home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / verdll / ver_info.txt < prev    next >
Encoding:
Text File  |  1994-10-15  |  16.8 KB  |  589 lines

  1.  
  2. Title: How to use functions in VER.DLL -- a Sample Application 
  3. Document Number: Q112731           Publ Date: 25-APR-1994 
  4. Product Name: Microsoft Visual Basic 
  5. Product Version:  2.00 3.00 
  6. Operating System: WINDOWS
  7.  
  8.  
  9.  
  10.  ------------------------------------------------------------------ 
  11.  The information in this article applies to:
  12.  
  13.  
  14.  - Standard and Professional Editions of Microsoft Visual Basic 
  15.    for Windows, versions 2.0 and 3.0 
  16.  ------------------------------------------------------------------
  17.  
  18.  
  19.  SUMMARY 
  20.  =======
  21.  
  22.  
  23.  This article contains code and instructions that show you how to 
  24.  create a sample application that uses some of the functions in VER.DLL 
  25.  to retrieve file information embedded into a file with the resource 
  26.  compiler (RC.EXE).
  27.  
  28.  
  29.  This Visual Basic applicatin was modeled after the Verstamp sample 
  30.  program included in the Microsoft Windows Software Development Kit (SDK).
  31.  
  32.  
  33.  Additional information can be found in the following documents:
  34.  
  35.  
  36.   - Microsoft Windows 3.1 Programmer's Reference, Vols. 2 & 3 
  37.   - Microsoft SDK Reference Help File (WIN31WH.HLP) from Windows 3.1 SDK 
  38.     or the Professional Edition of Visual Basic version 2.0 or 3.0.
  39.  
  40.  
  41.  MORE INFORMATION 
  42.  ================
  43.  
  44.  
  45.  Instead of offering this article in a number of steps, we have modified 
  46.  our usual format to make it easier for you to create and use this Visual 
  47.  Basic application. Therefore, the three files you need (VERINFO.BAS, 
  48.  VERINFO1.FRM, VERINFO2.FRM) are listed below so you can easily copy them 
  49.  into a text editor and save them as separate files. Instructions for how 
  50.  to use the files are embedded in the files as comments.
  51.  
  52.  
  53.  VERINFO.BAS 
  54.  -----------
  55.  
  56.  
  57.  ' Place the following code in a single text file called VERINFO.BAS 
  58.  ' 
  59.  ' The Global constants below are defined in the VER.H header file, also 
  60.  ' included in Microsoft C/C++ 7.0, and the Windows SDK. 
  61.  ' 
  62.  ' NOTE: After copying this into a file in a text editor, modify each 
  63.  ' Declare statements so that each one uses only one, single line.
  64.  
  65.  
  66.  Type VS_VERSION 
  67.     wLength            As Integer 
  68.     wValueLength       As Integer 
  69.     szKey              As String * 16 ' "VS_VERSION_INFO" 
  70.     dwSignature        As Long        ' VS_FIXEDFILEINFO struct 
  71.     dwStrucVersion     As Long 
  72.     dwFileVersionMS    As Long 
  73.     dwFileVersionLS    As Long 
  74.     dwProductVersionMS As Long 
  75.     dwProductVersionLS As Long 
  76.     dwFileFlagsMasks   As Long 
  77.     dwFileFlags        As Long 
  78.     dwFileOS           As Long 
  79.     dwFileType         As Long 
  80.     dwFileSubType      As Long 
  81.     dwFileDateMS       As Long 
  82.     dwFileDateLS       As Long 
  83.  End Type
  84.  
  85.  
  86.  Declare Function GetFileVersionInfo% Lib "Ver.dll" (ByVal Filename$, 
  87.     ByVal dwhandle&, ByVal cbBuff&, ByVal lpvData$) 
  88.  Declare Function GetFileVersionInfoSize& Lib "Ver.dll" 
  89.     (ByVal Filename$, dwhandle&) 
  90.  Declare Sub hmemcpy Lib "kernel" (hpvDest As Any, hpvSrc As Any, 
  91.     ByVal cbBytes&) 
  92.  Declare Function GetSystemDirectory% Lib "kernel" 
  93.     (ByVal Path$, ByVal cbBytes%)
  94.  
  95.  
  96.  ' **** VS_VERSION.dwFileFlags **** 
  97.  Global Const VS_FF_DEBUG = &H1& 
  98.  Global Const VS_FF_PRERELEASE = &H2& 
  99.  Global Const VS_FF_PATCHED = &H4& 
  100.  Global Const VS_FF_PRIVATEBUILD = &H8& 
  101.  Global Const VS_FF_INFOINFERRED = &H10&
  102.  Global Const VS_FF_SPECIALBUILD = &H20&
  103.  
  104.  
  105.  ' **** VS_VERSION.dwFileOS **** 
  106.  Global Const VOS_UNKNOWN = &H0& 
  107.  Global Const VOS_DOS = &H10000 
  108.  Global Const VOS_OS216 = &H20000 
  109.  Global Const VOS_OS232 = &H30000 
  110.  Global Const VOS_NT = &H40000
  111.  
  112.  
  113.  Global Const VOS__BASE = &H0& 
  114.  Global Const VOS__WINDOWS16 = &H1& 
  115.  Global Const VOS__PM16 = &H2& 
  116.  Global Const VOS__PM32 = &H3& 
  117.  Global Const VOS__WINDOWS32 = &H4&
  118.  
  119.  
  120.  Global Const VOS_DOS_WINDOWS16 = &H10001 
  121.  Global Const VOS_DOS_WINDOWS32 = &H10004 
  122.  Global Const VOS_OS216_PM16 = &H20002 
  123.  Global Const VOS_OS232_PM32 = &H30003 
  124.  Global Const VOS_NT_WINDOWS32 = &H40004
  125.  
  126.  
  127.  ' **** VS_VERSION.dwFileType **** 
  128.  Global Const VFT_UNKNOWN = &H0& 
  129.  Global Const VFT_APP = &H1& 
  130.  Global Const VFT_DLL = &H2& 
  131.  Global Const VFT_DRV = &H3& 
  132.  Global Const VFT_FONT = &H4& 
  133.  Global Const VFT_VXD = &H5& 
  134.  Global Const VFT_STATIC_LIB = &H7&
  135.  
  136.  
  137.  ' **** VS_VERSION.dwFileSubtype for VFT_WINDOWS_DRV **** 
  138.  Global Const VFT2_UNKNOWN = &H0& 
  139.  Global Const VFT2_DRV_PRINTER = &H1& 
  140.  Global Const VFT2_DRV_KEYBOARD = &H2& 
  141.  Global Const VFT2_DRV_LANGUAGE = &H3& 
  142.  Global Const VFT2_DRV_DISPLAY = &H4& 
  143.  Global Const VFT2_DRV_MOUSE = &H5& 
  144.  Global Const VFT2_DRV_NETWORK = &H6& 
  145.  Global Const VFT2_DRV_SYSTEM = &H7& 
  146.  Global Const VFT2_DRV_INSTALLABLE = &H8& 
  147.  Global Const VFT2_DRV_SOUND = &H9& 
  148.  Global Const VFT2_DRV_COMM = &HA&
  149.  
  150.  
  151.  ' **** VS_VERSION.dwFileSubtype for VFT_WINDOWS_FONT **** 
  152.  Global Const VFT2_FONT_RASTER = &H1& 
  153.  Global Const VFT2_FONT_VECTOR = &H2& 
  154.  Global Const VFT2_FONT_TRUETYPE = &H3&
  155.  
  156.  
  157.  ' **** Global variables used in both forms **** 
  158.  Global Filename$ 
  159.  Global Directory$ 
  160.  Global FileVer$ 
  161.  Global ProdVer$ 
  162.  Global FileFlags$ 
  163.  Global FileOS$ 
  164.  Global FileType$ 
  165.  Global FileSubType$
  166.  
  167.  
  168.  VERINFO1.FRM 
  169.  ------------
  170.  
  171.  
  172.  ' The following is a text dump of the form VERINFO1. It includes the form 
  173.  ' and control description as well as necessary Function and Sub procedures. 
  174.  ' Save the code in a single TEXT file called VERINFO1.FRM and you will 
  175.  ' be able to load it as a form in Visual Basic. 
  176.  ' 
  177.  ' NOTE: To make the code fit in this article, some of the lines are listed 
  178.  ' using multiple lines. After copying the code into a file in a text editor 
  179.  ' modify it to ensure that all lines of code exist as one, single line 
  180.  ' in the file. Otherwise, you will receive errors when loading the form in 
  181.  ' Visual Basic.
  182.  
  183.  
  184.  Begin Form Form1 
  185.     BorderStyle     =   1  'Fixed Single 
  186.     Caption         =   "VerInfo Demo" 
  187.     ClientHeight    =   4290 
  188.     ClientLeft      =   2340 
  189.     ClientTop       =   2160 
  190.     ClientWidth     =   3855 
  191.     Height          =   4695 
  192.     Left            =   2280 
  193.     LinkMode        =   1  'Source 
  194.     LinkTopic       =   "Form1" 
  195.     ScaleHeight     =   17.875 
  196.     ScaleMode       =   4  'Character 
  197.     ScaleWidth      =   32.125 
  198.     Top             =   1815 
  199.     Width           =   3975 
  200.     Begin DriveListBox Drive1 
  201.        Height          =   288 
  202.        Left            =   1836 
  203.        TabIndex        =   7 
  204.        Top             =   3792 
  205.        Width           =   1908 
  206.     End 
  207.     Begin DirListBox Dir1 
  208.        Height          =   1884 
  209.        Left            =   1830 
  210.        TabIndex        =   5 
  211.        Top             =   1428 
  212.        Width           =   1896 
  213.     End 
  214.     Begin FileListBox File1 
  215.        Height          =   2955 
  216.        Left            =   120 
  217.        TabIndex        =   3 
  218.        Top             =   984 
  219.        Width           =   1575 
  220.     End 
  221.     Begin TextBox Text1 
  222.        Height          =   288 
  223.        Left            =   1092 
  224.        TabIndex        =   1 
  225.        Text            =   "*.*" 
  226.        Top             =   204 
  227.        Width           =   2544 
  228.     End 
  229.     Begin Label Label1 
  230.        Caption         =   "Dri&ves:" 
  231.        Height          =   216 
  232.        Index           =   4 
  233.        Left            =   1830 
  234.        TabIndex        =   6 
  235.        Top             =   3480 
  236.        Width           =   660 
  237.     End 
  238.     Begin Label Label1 
  239.        Caption         =   "&Directories:" 
  240.        Height          =   192 
  241.        Index           =   3 
  242.        Left            =   1830 
  243.        TabIndex        =   4 
  244.        Top             =   1104 
  245.        Width           =   1236 
  246.     End 
  247.     Begin Label Label1 
  248.        Caption         =   "c:\" 
  249.        Height          =   204 
  250.        Index           =   2 
  251.        Left            =   1830 
  252.        TabIndex        =   8 
  253.        Top             =   648 
  254.        Width           =   1884 
  255.     End 
  256.     Begin Label Label1 
  257.        Caption         =   "&Files:" 
  258.        Height          =   204 
  259.        Index           =   0 
  260.        Left            =   120 
  261.        TabIndex        =   2 
  262.        Top             =   648 
  263.        Width           =   612 
  264.     End 
  265.     Begin Label Label1 
  266.        Caption         =   "File&Name:" 
  267.        Height          =   204 
  268.        Index           =   1 
  269.        Left            =   120 
  270.        TabIndex        =   0 
  271.        Top             =   252 
  272.        Width           =   936 
  273.     End 
  274.  End
  275.  
  276.  
  277.  Sub Dir1_Change () 
  278.     File1.Path = Dir1.Path 
  279.     Label1(2).Caption = File1.Path 
  280.  End Sub
  281.  
  282. b Sub DisplayVerInfo () 
  283.     Dim X As VS_VERSION
  284.  
  285.  
  286.     '*** Get Version Info **** 
  287.     FileVer$ = "": ProdVer$ = "": FileFlags$ = "" 
  288.     FileOS$ = "": FileType$ = "": FileSubType$ = "" 
  289.     FileName$ = File1.List(File1.ListIndex) 
  290.     Directory$ = Label1(2).Caption 
  291.     FullFileName$ = Label1(2).Caption + "\" + FileName$ 
  292.     BufSize& = GetFileVersionInfoSize(FullFileName$, dwHandle&) 
  293.     If BufSize& = 0 Then 
  294.        MsgBox "No Version Info available!" 
  295.        Exit Sub 
  296.     End If 
  297.     lpvData$ = Space$(BufSize&) 
  298.     r% = GetFileVersionInfo(FullFileName$, dwHandle&, BufSize&, lpvData$) 
  299.     hmemcpy X, ByVal lpvData$, Len(X)
  300.  
  301.  
  302.     '**** Determine File Version number **** 
  303.     FileVer$ = LTrim$(Str$(HIWORD(X.dwFileVersionMS))) + "." 
  304.     FileVer$ = FileVer$ + LTrim$(Str$(LOWORD(X.dwFileVersionMS))) + "." 
  305.     FileVer$ = FileVer$ + LTrim$(Str$(HIWORD(X.dwFileVersionLS))) + "." 
  306.     FileVer$ = FileVer$ + LTrim$(Str$(LOWORD(X.dwFileVersionLS)))
  307.  
  308.  
  309.     '**** Determine Product Version number **** 
  310.     ProdVer$ = LTrim$(Str$(HIWORD(X.dwFileVersionMS))) + "." 
  311.     ProdVer$ = ProdVer$ + LTrim$(Str$(LOWORD(X.dwProductVersionMS))) + "." 
  312.     ProdVer$ = ProdVer$ + LTrim$(Str$(HIWORD(X.dwProductVersionLS))) + "." 
  313.     ProdVer$ = ProdVer$ + LTrim$(Str$(LOWORD(X.dwProductVersionLS)))
  314.  
  315.  
  316.     '**** Determine Boolean attributes of File **** 
  317.     If X.dwFileFlags And VS_FF_DEBUG Then FileFlags$ = "DeBug" 
  318.     If X.dwFileFlags And VS_FF_PRERELEASE Then FileFlags$ = 
  319.        FileFlags$ + "PreRel" 
  320.     If X.dwFileFlags And VS_FF_PATCHED Then FileFlags$ = 
  321.        FileFlags$ + "Patched" 
  322.     If X.dwFileFlags And VS_FF_PRIVATEBUILD Then FileFlags$ = 
  323.        FileFlags$ +  "Private" 
  324.     If X.dwFileFlags And VS_FF_INFOINFERRED Then FileFlags$ = 
  325.        FileFlags$ + "Info" 
  326.     If X.dwFileFlags And VS_FF_DEBUG Then FileFlags$ = 
  327.        FileFlags$ + "Special"
  328.  
  329.  
  330.     If X.dwFileFlags And &HFFFFFF00 Then FileFlags$ = FileFlags$ + "Unknown"
  331.  
  332.  
  333.     '**** Determine OS for which file was designed **** 
  334.     Select Case X.dwFileOS 
  335.        Case VOS_DOS_WINDOWS16 
  336.           FileOS$ = "DOS-Win16" 
  337.        Case VOS_DOS_WINDOWS32 
  338.           FileOS$ = "DOS=Win32" 
  339.        Case VOS_OS216_PM16 
  340.           FileOS$ = "OS/2-16 PM-16" 
  341.        Case VOS_OS232_PM32 
  342.           FileOS$ = "OS/2-32 PM-32" 
  343.        Case VOS_NT_WINDOWS32 
  344.           FileOS$ = "NT-Win32" b       Case Else 
  345.           FileOS$ = "Unknown" 
  346.     End Select
  347.  
  348.  
  349.  
  350.     '**** Determine Type and SubType of File **** 
  351.     Select Case X.dwFileType 
  352.        Case VFT_APP 
  353.           FileType$ = "App" 
  354.        Case VFT_DLL 
  355.           FileType$ = "DLL" 
  356.        Case VFT_DRV 
  357.           FileType$ = "Driver" 
  358.           Select Case X.dwFileSubType 
  359.              Case VFT2_DRV_PRINTER 
  360.                 FileSubType$ = "Printer drv" 
  361.              Case VFT2_DRV_KEYBOARD 
  362.                 FileSubType$ = "Keyboard drv" 
  363.              Case VFT2_DRV_LANGUAGE 
  364.                 FileSubType$ = "Language drv" 
  365.              Case VFT2_DRV_DISPLAY 
  366.                 FileSubType$ = "Display drv" 
  367.              Case VFT2_DRV_MOUSE 
  368.                 FileSubType$ = "Mouse drv" 
  369.              Case VFT2_DRV_NETWORK 
  370.                 FileSubType$ = "Network drv" 
  371. ALLABLE 
  372.                 FileSubType$ = "Installable" 
  373.              Case VFT2_DRV_SOUND 
  374.                 FileSubType$ = "Sound drv" 
  375.              Case VFT2_DRV_COMM 
  376.                 FileSubType$ = "Comm drv" 
  377.              Case VFT2_UNKNOWN 
  378.                 FileSubType$ = "Unknown" 
  379.           End Select 
  380.        Case VFT_FONT 
  381.           FileType$ = "Font" 
  382.           Select Case X.dwFileSubType 
  383.              Case VFT_FONT_RASTER 
  384.                 FileSubType$ = "Raster Font" 
  385.              Case VFT_FONT_VECTOR 
  386.                 FileSubType$ = "Vector Font" 
  387.              Case VFT_FONT_TRUETYPE 
  388.                 FileSubType$ = "TrueType Font" 
  389.           End Select 
  390.        Case VFT_VXD 
  391.           FileType$ = "VxD" 
  392.        Case VFT_STATIC_LIB 
  393.           FileType$ = "Lib" 
  394.        Case Else 
  395.           FileType$ = "Unknown" 
  396.     End Select
  397.  
  398.  
  399.     Form2.Show 1 
  400.  End Sub
  401.  
  402.  
  403.  Sub Drive1_Change () 
  404.     Dir1.Path = Drive1.Drive 
  405.     File1.Path = Dir1.Path 
  406.     Label1(2).Caption = File1.Path 
  407.  End Sub
  408.  
  409.  
  410.  Sub File1_Click () 
  411.     Text1.Text = File1.List(File1.ListIndex) 
  412.  End Sub
  413.  
  414.  
  415.  Sub File1_DblClick () 
  416.     DisplayVerInfo 
  417.  End Sub
  418.  
  419.  
  420.  Sub File1_PathChange () 
  421.     Text1.Text = "*.*" 
  422.     File1.Pattern = "*.*" 
  423.  End Sub
  424.  
  425.  
  426.  Sub Form_Load () 
  427.     Dim Buffer$
  428.  
  429.  
  430.     ' **** Set Default Dir to Windows System Subdirectory **** 
  431.     Buffer$ = Space$(256) 
  432.     r% = GetSystemDirectory(Buffer$, Len(Buffer$)) 
  433.     Dir1.Path = Buffer$ 
  434.     File1.Path = Buffer$ 
  435.     Drive1.Drive = Left$(Buffer$, 1) 
  436.  End Sub
  437.  
  438.  
  439.  Function HIWORD (X As Long) As Integer 
  440.     HIWORD = X \ &HFFFF& 
  441.  End Function
  442.  
  443.  
  444.  Function LOWORD (X As Long) As Integer 
  445.     LOWORD = X And &HFFFF& 
  446.  End Function
  447.  
  448.  
  449.  Sub Text1_KeyPress (KeyAscii As Integer) 
  450.     If KeyAscii = 13 Then 
  451.        File1.Pattern = Text1.Text 
  452.        KeyAscii = 0 
  453.        If File1.ListCount = 1 Then DisplayVerInfo 
  454.        If File1.ListCount = 0 Then 
  455.           MsgBox "Invalid Filename" 
  456.           File1.Pattern = "*.*" 
  457.           Text1.Text = "*.*" 
  458.        End If 
  459.        File1.SetFocus 
  460.     End If 
  461.  End Sub
  462.  
  463.  
  464.  
  465.  VERINFO2.FRM 
  466.  ------------
  467.  
  468.  
  469.  ' The following is a text dump of the form VERINFO2. It includes the form 
  470.  ' and control description as well as necessary Function and Sub procedures. 
  471.  ' Save the code in a single text file called VERINFO2.FRM and you will 
  472.  ' be able to load it as a form in Visual Basic. 
  473.  ' 
  474.  VERSION 2.00 
  475.  Begin Form Form2 
  476.     BorderStyle     =   1  'Fixed Single 
  477.     Caption         =   "File Version Info" 
  478.     ClientHeight    =   3345 
  479.     ClientLeft      =   6630 
  480.     ClientTop       =   2175 
  481.     ClientWidth     =   4500 
  482.     FontBold        =   0   'False 
  483.     FontItalic      =   0   'False 
  484.     FontName        =   "MS Sans Serif" 
  485.     FontSize        =   8.25 
  486.     FontStrikethru  =   0   'False 
  487.     FontUnderline   =   0   'False 
  488.     Height          =   3750 
  489.     Left            =   6570 
  490.     LinkMode        =   1  'Source 
  491.     LinkTopic       =   "Form3" 
  492.     MaxButton       =   0   'False 
  493.     MinButton       =   0   'False 
  494.     ScaleHeight     =   13.938 
  495.     ScaleMode       =   4  'Character 
  496.     ScaleWidth      =   37.5 
  497.     Top             =   1830 
  498.     Width           =   4620 
  499.     Begin CommandButton Command1 
  500.        Caption         =   "OK" 
  501.        Height          =   372 
  502.        Left            =   1680 
  503.        TabIndex        =   0 
  504.        Top             =   2880 
  505.        Width           =   1452 
  506.     End 
  507.  End
  508.  
  509.  
  510.  Sub Command1_Click () 
  511.     Form2.Hide 
  512.  End Sub
  513.  
  514.  
  515.  Sub Command1_GotFocus () 
  516.    Form_Paint 
  517.  End Sub
  518.  
  519.  
  520.  Sub Form_Paint () 
  521.     Form2.CurrentX = 2
  522.     Form2.CurrentY = 1 
  523.     Form2.Print "FileName:" 
  524.     Form2.CurrentX = 2 
  525.     Form2.Print "Directory:" 
  526.     Form2.CurrentX = 2 
  527.     Form2.Print "File Version:" 
  528.     Form2.CurrentX = 2 
  529.     Form2.Print "Product Version:" 
  530.     Form2.CurrentX = 2 
  531.     Form2.Print "File Flags:" 
  532.     Form2.CurrentX = 2 
  533.     Form2.Print "File OS:" 
  534.     Form2.CurrentX = 2 
  535.     Form2.Print "File Type:" 
  536.     Form2.CurrentX = 2 
  537.     Form2.Print "File Sub-type:"
  538.  
  539.  
  540.     Form2.CurrentX = 18 
  541.     Form2.CurrentY = 1 
  542.     Form2.Print FileName$ 
  543.     Form2.CurrentX = 18 
  544.     Form2.Print Directory$ 
  545.     Form2.CurrentX = 18 
  546.     Form2.Print FileVer$ 
  547.     Form2.CurrentX = 18 
  548.     Form2.Print ProdVer$ 
  549.     Form2.CurrentX = 18 
  550.     Form2.Print FileFlags$ 
  551.     Form2.CurrentX = 18 
  552.     Form2.Print FileOS$ 
  553.     Form2.CurrentX = 18 
  554.     Form2.Print FileType$ 
  555.     Form2.CurrentX = 18 
  556.     Form2.Print FileSubType$ 
  557.  End Sub
  558.  
  559.  
  560.  How to Create and Run the Program 
  561.  ---------------------------------
  562.  
  563.  
  564.  1. Start Visual Basic. Form1 is created by default.
  565.  
  566.  
  567.  2. From the File menu, choose Remove File to remove Form1.
  568.  
  569.  
  570.  3. From the File menu, choose Add File... to and add VERINFO.BAS
  571.  
  572.  
  573.  4. Repeat step 3 to add VERINFO1.FRM and VERINFO2.FRM to the project.
  574.  
  575.  
  576.  5. From the Options menu, choose Project... and set Start Up Form 
  577.     to Form1.
  578.  
  579.  
  580.  6. Run the application.
  581.  
  582.  
  583.  Additional reference words: 2.00 3.00 codesmpl 
  584.  KBCategory: APrg 
  585.  KBSubCategory: APrgWindow
  586.  
  587.  
  588. COPYRIGHT Microsoft Corporation, 1994.
  589.